<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head th:replace="common/layout :: common_header(~{::title},~{::link})">
<title>新建机构</title>
</head>
<body>
	<div class="main-container">
		<div class="main-content-inner">
			<div class="page-content">
				<form class="form-horizontal" role="form" id="AddForm"
					method="post" th:action="@{/sys/office/save}">
					 <input id="areaId" name="areaId"   type="hidden" />
					<input id="p_Id" name="parentId"   type="hidden" th:value="${psysOffice.id!=null}?${psysOffice.id}:''" />
					<table
						class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
						<tr>
							<td class="width-15 active"><label class="pull-right control-label"
								for="parentName">上级机构</label></td>
							<td class="width-35">
								<div class="input-group" style="width: 100%">
									<input class="form-control" id="parentName" name="parentName"
										type="text" th:value="${psysOffice.name}" readonly="readonly"/> <span
										class="input-group-btn">
										<button type="button" id="officeButton"
											class="btn   btn-primary  ">
											<i class="fa fa-search"></i>
										</button>
										 <button type="button" id="officeDelButton" class="close" data-dismiss="alert" style="position: absolute; top: 5px; right: 53px; z-index: 999; display: block;">×</button>
									</span>
								</div>
							</td>

							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_name"><font color="red">*</font>归属区域</label></td>
							<td class="width-35"><div class="input-group" style="width: 100%">
									<input class="form-control" id="areaName" name="areaName"
										type="text" readonly="readonly" /> <span
										class="input-group-btn">
										<button type="button" id="areaButton"
											class="btn   btn-primary  ">
											<i class="fa fa-search"></i>
										</button>
										 <button type="button" id="areaDelButton" class="close" data-dismiss="alert" style="position: absolute; top: 5px; right: 53px; z-index: 999; display: block;">×</button>
									</span>
								</div>
								</td>
						</tr>
						<tr>
							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_name"><font color="red">*</font>机构名称:</label></td>
							<td class="width-35"><input class="form-control"
								id="ds_name" name="name" type="text"  
								required /></td>
							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_code">机构编码</label></td>
							<td class="width-35"><input class="form-control"
								id="ds_code" name="code" type="text"  />
							</td>
						</tr>
						<tr>
							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_type">机构类型</label></td>
							<td class="width-35">
								 <dict:select code="orgType" value="2" name="type"  class="form-control" id="ds_type"></dict:select> 
								  
								  </td>
							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_grade">机构级别</label></td>
							<td class="width-35"> 
								<dict:select code="orgLevel" value="2" name="grade"  class="form-control" id="ds_grade"></dict:select> 
								  
							</td>
						</tr>
						<tr>
						<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_type">是否可用</label></td>
							<td class="width-35"><select class="form-control" name="useable">
							<option value="0">可用</option>
							<option value="1">禁用</option>
							</select>
							</td>
							<td class="width-15 active"><label class="pull-right  control-label"
								for="ds_remarks">备注</label></td>
							<td class="width-35"><textarea class="form-control"
									id="ds_remarks" name="remarks"  ></textarea>
							</td>
						</tr>
					</table>


					<div class="clearfix ">
						<div class="center">
							<button class="btn btn-info" type="submit" id="submitBtn">
								<i class="ace-icon fa fa-check bigger-110"></i> 保存
							</button>

							&nbsp; &nbsp; &nbsp;
							<button class="btn" type="button" id="closeWin">
								<i class="ace-icon fa fa-del bigger-110"></i> 关闭
							</button>
						</div>
					</div>
				</form>
				<!-- /.col -->
			</div>

		</div>
		<!-- end main container -->
	</div>

	<div th:replace="common/commonJS"></div>
	<script type="text/javascript">
	$(document).ready(function(){
	$("#officeButton, #parentName").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#officeButton").hasClass("disabled")){
			return true;
		}
		// 正常打开	
		top.layer.open({
		    type: 2, 
		    area: ['300px', '420px'],
		    title:"选择机构",
		    ajaxData:{selectIds: $("#p_Id").val()},
		    content: ctx+"sys/treeselect?url="+encodeURIComponent("sys/office/treeData")+"&module=&checked=&extId=&isAll=&allowSearch=" ,
		    btn: ['确定', '关闭']
    	       ,yes: function(index, layero){ //或者使用btn1
						var tree = layero.find("iframe")[0].contentWindow.tree;//h.find("iframe").contents();
						var ids = [], names = [], nodes = [];
						if ("" == "true"){
							nodes = tree.get_checked(true);
						}else{
							nodes = tree.get_selected(true);
						}
						for(var i=0; i<nodes.length; i++) {//
							ids.push(nodes[i].id);
							names.push(nodes[i].text);//
							break; // 如果为非复选框选择，则返回第一个选择  
						}
						$("#p_Id").val(ids.join(",").replace(/u_/ig,""));
						$("#parentName").val(names.join(","));
						$("#parentName").focus();
						top.layer.close(index);
				    	       },
    	cancel: function(index){ //或者使用btn2
    	           //按钮【按钮二】的回调
    	       }
		}); 
	
	});
	
	$("#officeDelButton").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#officeButton").hasClass("disabled")){
			return true;
		}
		// 清除	
		$("#p_Id").val("");
		$("#parentName").val("");
		$("#parentName").focus();
	
	});
	
	$("#areaButton, #areaName").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#areaButton").hasClass("disabled")){
			return true;
		}
		// 正常打开	
		top.layer.open({
		    type: 2, 
		    area: ['300px', '420px'],
		    title:"选择区域",
		    ajaxData:{selectIds: $("#areaId").val()},
		    content: ctx+"sys/treeselect?url="+encodeURIComponent("sys/area/treeData")+"&module=&checked=&extId=&isAll=&allowSearch=" ,
		    btn: ['确定', '关闭']
    	       ,yes: function(index, layero){ //或者使用btn1
						var tree = layero.find("iframe")[0].contentWindow.tree;//h.find("iframe").contents();
						var ids = [], names = [], nodes = [];
						if ("" == "true"){
							nodes = tree.get_checked(true);
						}else{
							nodes = tree.get_selected(true);
						}
						for(var i=0; i<nodes.length; i++) {//
							ids.push(nodes[i].id);
							names.push(nodes[i].text);//
							break; // 如果为非复选框选择，则返回第一个选择  
						}
						$("#areaId").val(ids.join(",").replace(/u_/ig,""));
						$("#areaName").val(names.join(","));
						$("#areaName").focus();
						top.layer.close(index);
				    	       },
    	cancel: function(index){ //或者使用btn2
    	           //按钮【按钮二】的回调
    	       }
		}); 
	
	});

	$("#areaDelButton").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#areaButton").hasClass("disabled")){
			return true;
		}
		// 清除	
		$("#areaId").val("");
		$("#areaName").val("");
		$("#areaName").focus();
	
	});
})
</script>
	<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	//关闭iframe
	$('#closeWin').click(function(){
	    top.layer.close(index);
	});
	    
	 $().ready(function() {
		    $("#AddForm").validate({
		    	submitHandler: function(form) { 
	        		//验证通过后 的js代码写在这里 
	        		
		    		 $(form).ajaxSubmit({
		                 dataType:"json",
		                 success:function( data ){
		                      if(data==1){
		                    	  top.layer.alert('保存成功') 
		                    	  top.layer.close(index);
		                    	  if(top.getActiveTab()[0]){
		                    		  top.getActiveTab()[0].contentWindow.refresh();
		                    	  }
		                    	  
		                      }else{
		                    	  top.layer.alert('保存失败')  
		                      }
		                        
		                    
		                   },
		                   error:function(xhr, status, error){
		                	   top.layer.alert('操作失败');
		                   }
		                 });
	         
	        		}
		    });
		});
	</script>
</body>
</html>